package com.uqbar.demo.components;

import java.awt.Color;

import com.uqbar.demo.calculos.Calculadora;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.demo.calculos.Punto;

public class Bolita extends GameComponent<GameScene> {
	private int speed = 200;
	private int diameter = 60;
	private Color color = Color.BLUE;
	
	private int sentidoEnY = 1;
	private int sentidoEnX = 1;

	public Bolita(int x, int y) {
		super(x, y);

		this.setAppearance(new Circle(this.color, this.diameter));
	}

	@Override
	public void update(DeltaState deltaState) {
		super.update(deltaState);

		Punto versor= new Calculadora().calcularVersor(
				new Punto(deltaState.getDelta() * this.speed * this.sentidoEnX , deltaState.getDelta() * (this.speed )* this.sentidoEnY));
		this.move(versor.getX() ,versor.getY() );

		// cuando toca el borde superior
		if(this.getY() > this.getGame().getDisplayHeight() - this.diameter) {
			this.sentidoEnY= this.sentidoEnY * (-1);
		}

		// cuando toca el borde inferior
		if((this.getY() < 1)) {
			this.sentidoEnY= this.sentidoEnY * (-1);
		}
		
		// cuando toca el borde izquierdo
		if(this.getX() > this.getGame().getDisplayWidth() - this.diameter){
			this.sentidoEnX= this.sentidoEnX * (-1);
		}
		
		// cuando toca el borde derecho
		if(this.getX() < 1){
			this.sentidoEnX= this.sentidoEnX * (-1);
		}		
	}
}